'''
Created on 2009-11-14

@author: Administrator
'''
from google.appengine.ext import db
from google.appengine.api import users
from mod.noname import NoName
from mod.tpl import Tpl
from mod.member import Member

class Index(Tpl):
    '''
    classdocs
    '''


    def get(self):
        '''
        Constructor
        '''
        topblogkey = self.request.get("top")
        noname = NoName()
        tplval = {"noname":noname}
        
        user = users.get_current_user()
        if user:
             member = Member().getMember(user)
             tplval['member'] = member
             tplval['isadmin'] = users.is_current_user_admin()
             tplval['logouturl'] = users.create_logout_url(self.request.uri)

        tplval['loginurl'] = users.create_login_url(self.request.uri)
        
        if topblogkey == "":   
            blogs = db.GqlQuery("select * from Blog where topblog=:1 order by createtime desc ","")
        else:
            pblog = db.get(topblogkey)
            if pblog :
                tplval["topblog"] = pblog
                blogs = db.GqlQuery("select * from Blog where topblog=:1 order by createtime desc ",topblogkey)
                if pblog.topblog == "":
                    tplval["returnurl"] = "/"
                else:
                    tplval["returnurl"] = "/?top="+pblog.topblog
            else:
                self.redirect("/")
        
        #self.setStylePath("style1")        
        tplval["blogs"] = blogs
        self.display("index.html", tplval)
        
    
            
        